﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WellBuilt.Model;
using WellBuilt.RequestHelper;
using WellBuilt.Service;

namespace WellBuilt.Controllers
{
    [Route("api/{controller}")]
    public class WellBuiltController : Controller
    {

        private ILogger<WellBuiltController> _Logger = null;
        private ILoggerFactory _Factory = null;
        public WellBuiltController(ILogger<WellBuiltController> logger, ILoggerFactory factory)
        {
            _Logger = logger;
            this._Factory = factory;
        }
        /// <summary>
        /// 平巷断面及支护
        /// </summary>
        /// <param name="sectionIn">平巷断面及支护实体类</param>
        /// <returns></returns>
        [HttpPost("TunnelSectionAction")]
        public string TunnelSectionAction([FromBody] TunnelSectionIn sectionIn)
        {
            try
            {
                _Logger.LogInformation($"平巷断面及支护方法传入参数：{JsonConvert.SerializeObject(sectionIn)}");
                //逻辑运算
                TunnelSectionOut SectionOut = TunnelSectionService.TunnelSectionResult(sectionIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, SectionOut, CodeInfo.GetDescription(ResultCode.SUCCESS));
                //TunnelSectionOut转换为string传出
                string values = JsonConvert.SerializeObject(result);
                _Logger.LogInformation($"平巷断面及支护方法传传出参数：{values}");
                return values;
            }
            catch(Exception ex)
            {
                _Logger.LogError(ex,"错误信息");
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }

        /// <summary>
        /// 锚杆设计计算
        /// </summary>
        /// <param name="boltIn">锚杆设计计算实体类</param>
        /// <returns></returns>
        [HttpPost("BoltAction")]
        public string BoltAction([FromBody] BoltIn boltIn)
        {
            try
            {
                BoltOut boltOut = BoltService.BoltResult(boltIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, boltOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }

        /// <summary>
        /// 构件重量计算
        /// </summary>
        /// <param name="componentIn">构件重量计算实体类</param>
        /// <returns></returns>
        [HttpPost("ComponentAction")]
        public string ComponentAction([FromBody] ComponentIn componentIn)
        {
            try
            {
                ComponentOut componentOut = ComponentService.ComponentResult(componentIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, componentOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }

        /// <summary>
        /// 水泥浆设计
        /// </summary>
        /// <param name="cementPasteIn">水泥浆设计实体类</param>
        /// <returns></returns>
        [HttpPost("CementPasteAction")]
        public string CementPasteAction([FromBody] CementPasteIn cementPasteIn)
        {
            try
            {
                CementPasteOut componentOut = CementPasteService.CementPasteResult(cementPasteIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, componentOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }

        /// <summary>
        /// 平台板计算
        /// </summary>
        /// <param name="platFormIn">平台板实体类</param>
        /// <returns></returns>
        [HttpPost("PlatFormAction")]
        public string PlatFormAction([FromBody] PlatFormIn platFormIn)
        {
            try
            {
                PlatFormOut platFormOut = PlatFormService.PlatFormResult(platFormIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, platFormOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }
        /// <summary>
        /// 风井装备
        /// </summary>
        /// <param name="VentShaftIn">风井装备实体类</param>
        /// <returns></returns>
        [HttpPost("VentShaftAction")]
        public string VentShaftAction([FromBody] VentShaftIn VentShaftIn)
        {
            try
            {
                VentShaftOut VentShaftOut = VentShaftService.VentShaftResult(VentShaftIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, VentShaftOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }
        /// <summary>
        /// 工字钢梁计算
        /// </summary>
        /// <param name="girderIn">工字钢梁实体类</param>
        /// <returns></returns>
        [HttpPost("GirderAction")]
        public string GirderAction([FromBody] GirderIn girderIn)
        {
            try
            {
                GirderOut girderOut = GirderService.GirderResult(girderIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, girderOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }
        /// <summary>
        /// 焊接吊车梁计算
        /// </summary>
        /// <param name="craneBeamIn">焊接吊车梁实体类</param>
        /// <returns></returns>
        [HttpPost("CraneBeamAction")]
        public string CraneBeamAction([FromBody] CraneBeamIn craneBeamIn)
        {            
            try
            {
                CraneBeamOut craneBeamOut = CraneBeamService.GirderResult(craneBeamIn);
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, craneBeamOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }

        /// <summary>
        /// 罐道及罐道梁
        /// </summary>
        /// <param name="cageGuideIn">罐道及罐道梁实体类</param>
        /// <returns></returns>
        [HttpPost("CageGuideAction")]
        public string CageGuideAction([FromBody] CageGuideIn cageGuideIn)
        {
            try
            {
                CageGuideOut cageGuideOut = CageGuideService.CageGuideResult(cageGuideIn);

                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, cageGuideOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }
        /// <summary>
        /// 混凝土梁计算
        /// </summary>
        /// <param name="concreteBeamIn">混凝土梁计算实体类</param>
        /// <returns></returns>
        [HttpPost("ConcreteBeamAction")]
        public string ConcreteBeamAction([FromBody] ConcreteBeamIn concreteBeamIn)
        {
            try
            {
                ConcreteBeamOut concreteBeamOut = ConcreteBeamService.ConcreteBeamResult(concreteBeamIn);

                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.SUCCESS, concreteBeamOut, CodeInfo.GetDescription(ResultCode.SUCCESS));

                string values = JsonConvert.SerializeObject(result);

                return values;
            }
            catch (Exception ex)
            {
                ResultMessage resultMessage = new();
                object result = resultMessage.SetResultMessage(ResultCode.FAIL, null, CodeInfo.GetDescription(ResultCode.FAIL));
                string values = JsonConvert.SerializeObject(result);
                return values;
            }
        }
    }
}
